<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-select v-model="query.enterpriseCode" clearable filterable placeholder="所属机构" style="width: 300px;" class="filter-item" >
          <el-option v-for="item in dict.enterprise_list" :key="item.id" :label="item.value +' - '+ item.label" :value="item.value"/>
        </el-select>
<!--        <el-select v-model="query.questionClassification" clearable filterable placeholder="请选择分类" style="width: 185px;" class="filter-item" >-->
<!--          <el-option v-for="item in dict.work_classification" :key="item.id" :label="item.label" :value="item.value"/>-->
<!--        </el-select>-->
        <el-select v-model="query.questionType" clearable filterable placeholder="请选择类型" style="width: 185px;" class="filter-item" >
          <el-option v-for="item in dict.work_type" :key="item.id" :label="item.label" :value="item.value"/>
        </el-select>
        <el-input v-model="query.questionDescription" clearable placeholder="工单描述" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"/>
        <el-input v-model="query.startUser" clearable placeholder="提问人" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"/>
        <el-input v-model="query.endUser" clearable placeholder="处理人" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"/>
        <el-select v-model="query.workStatus" clearable filterable placeholder="工单状态" style="width: 185px;" class="filter-item" >
          <el-option v-for="item in dict.work_status" :key="item.id" :label="item.label" :value="item.value"/>
        </el-select>
<!--        <date-range-picker v-model="query.endTime" start-placeholder="endTimeStart" end-placeholder="endTimeStart" class="date-item"/>-->
<!--        <date-range-picker v-model="query.startTime" start-placeholder="startTimeStart" end-placeholder="startTimeStart" class="date-item"/>-->
        <rrOperation :crud="crud"/>
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission">
        <!-- 任务日志 -->
        <el-button slot="right" plain class="filter-item" size="small" type="info" icon="el-icon-tickets" @click="importDetail">导入</el-button>
      </crudOperation>

      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="700px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="100px">
          <el-form-item label="所属机构">
            <el-select v-model="form.enterpriseCode" clearable filterable placeholder="请选择机构" style="width: 100%;">
              <el-option v-for="item in dict.enterprise_list" :key="item.id" :label="item.value +' - '+ item.label" :value="item.value"/>
            </el-select>
          </el-form-item>
<!--          <el-form-item label="所属分类" prop="questionClassification">-->
<!--            <el-select v-model="form.questionClassification" clearable filterable placeholder="请选择分类" style="width: 100%;">-->
<!--              <el-option v-for="item in dict.work_classification" :key="item.id" :label="item.label" :value="item.value"/>-->
<!--            </el-select>-->
<!--          </el-form-item>-->
          <el-form-item label="所属类型" prop="questionType">
            <el-select v-model="form.questionType" clearable filterable placeholder="请选择类型" style="width: 100%;">
              <el-option v-for="item in dict.work_type" :key="item.id" :label="item.label" :value="item.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="工单描述" prop="questionDescription">
            <el-input v-model="form.questionDescription" clearable :rows="6" type="textarea" style="width: 100%;"/>
          </el-form-item>
          <el-form-item label="解决办法" prop="questionSolution">
            <el-input v-model="form.questionSolution" clearable :rows="6" type="textarea" style="width: 100%;"/>
          </el-form-item>


          <el-form-item label="提 问 人" prop="startUser">
            <el-input v-model="form.startUser" clearable style="width: 100%;"/>
          </el-form-item>
          <el-form-item label="提问时间" prop="startTime">
            <el-date-picker v-model="form.startTime"  type="datetime" style="width: 100%;"/>
          </el-form-item>
          <el-form-item label="处 理 人" prop="endUser">
            <el-input v-model="form.endUser" clearable style="width: 100%;"/>
          </el-form-item>
          <el-form-item label="处理时间" prop="endTime">
            <el-date-picker v-model="form.endTime" type="datetime" style="width: 100%;" />
          </el-form-item>
          <el-form-item label="工时(人/天)" prop="workHours">
            <el-input v-model="form.workHours" clearable style="width: 100%;"/>
          </el-form-item>
          <el-form-item label="工单状态" prop="workStatus">
            <el-select v-model="form.workStatus" clearable filterable placeholder="请选择工单状态" style="width: 100%;">
              <el-option v-for="item in dict.work_status" :key="item.id" :label="item.label" :value="item.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="明细备注">
            <el-input v-model="form.remark" clearable style="width: 100%;"/>
          </el-form-item>
          <el-form-item label="明细排序" prop="orderNumber">
            <el-input-number :min="1" v-model="form.orderNumber" style="width: 100%;"/>
          </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="info" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table border stripe highlight-current-row ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;"
                @selection-change="crud.selectionChangeHandler"  @cell-dblclick="toDetail"  max-height="665px">
        <el-table-column align="center" type="selection" width="55" />
        <el-table-column align="center" min-width="80" prop="orderNumber" label="排序" />
<!--        <el-table-column align="center" min-width="120" prop="questionClassification" label="分类">-->
<!--          <template slot-scope="scope">{{ dict.label.work_classification[scope.row.questionClassification] }}</template>-->
<!--        </el-table-column>-->
        <el-table-column  align="center" min-width="120"  prop="questionType" label="类型">
          <template slot-scope="scope">{{ dict.label.work_type[scope.row.questionType] }}</template>
        </el-table-column>
        <el-table-column align="center" min-width="100" prop="startUser" label="提问人" />
        <el-table-column align="center" min-width="100" prop="workStatus" label="工单状态" >
          <template slot-scope="scope">{{ dict.label.work_status[scope.row.workStatus] }}</template>
        </el-table-column>
        <el-table-column align="left" min-width="700" prop="questionDescription" label="工单描述" show-overflow-tooltip />

        <el-table-column align="center" min-width="100" prop="endUser" label="处理人" />
        <el-table-column align="center" min-width="170" prop="endTime" label="处理时间" />
        <el-table-column align="center" min-width="100" prop="workHours" label="工时(人/天)" />
        <el-table-column align="center" min-width="170" prop="startTime" label="提问时间" />
        <el-table-column align="center" min-width="170" prop="createTime" label="创建日期" />
        <el-table-column align="center" min-width="300" :show-overflow-tooltip="true" prop="enterpriseCode" label="所属机构" >
          <template slot-scope="scope">{{ dict.label.enterprise_list[scope.row.enterpriseCode] }}</template>
        </el-table-column>
        <el-table-column align="center" min-width="200" prop="remark" label="备注" />
        <el-table-column v-if="checkPer(['admin','workOrderDetail:edit','workOrderDetail:del'])" label="操作" min-width="200px" fixed="right" align="center" >
          <template slot-scope="scope">
            <udOperation :data="scope.row" :permission="permission" />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>
<script>
import crudWorkOrderDetail from '@/api/workOrder/workOrderDetail'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm =
  {
    workDetailId: null,
    workHeadId: null,
    workStatus:0,
    questionDescription: null,
    questionSolution: null,
    remark: null,
    isDelete: 1,
    orderNumber: null,
    startUser: null,
    endUser: null,
    endTime: null,
    startTime: null,
    workHours: null,
    questionType: null,
    enterpriseCode: null,
    createBy: null,
    updateBy: null,
    createTime: null,
    updateTime: null
  }

export default {
  name: 'WorkOrderDetail',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['work_type', 'enterprise_list', 'work_status'],
  cruds() {
    return CRUD({ title: '工单明细', url: 'api/workOrderDetail', idField: 'workDetailId', sort: 'orderNumber,desc', crudMethod: { ...crudWorkOrderDetail }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'workOrderDetail:add'],
        edit: ['admin', 'workOrderDetail:edit'],
        del: ['admin', 'workOrderDetail:del']
      },
      rules: {
        workDetailName: [{ required: true, message: '工单标题不能为空', trigger: 'blur' }],
        questionDescription: [{ required: true, message: '工单描述不能为空', trigger: 'blur' }],
        questionSolution: [{ required: true, message: '解决办法不能为空', trigger: 'blur' }],
        startUser: [{ required: true, message: '提问人不能为空', trigger: 'blur' }],
        endUser: [{ required: true, message: '处理人不能为空', trigger: 'blur' }],
        endTime: [{ required: true, message: '处理时间不能为空', trigger: 'blur' }],
        startTime: [{ required: true, message: '提问时间不能为空', trigger: 'blur' }],
        questionClassification: [{ required: true, message: '分类不能为空', trigger: 'blur' }],
        questionType: [{ required: true, message: '类型不能为空', trigger: 'blur' }]
      },
      queryTypeOptions: [
        { key: 'workDetailId', display_name: '工单明细主键id' },
        { key: 'workHeadId', display_name: '工单头id' },
        { key: 'projectName', display_name: '所属项目名称' },
        { key: 'projectId', display_name: '所属项目ID' },
        { key: 'workDetailName', display_name: '工单标题' },
        { key: 'startUser', display_name: '提问人' },
        { key: 'endUser', display_name: '处理人' },
        { key: 'questionClassification', display_name: '分类' },
        { key: 'questionType', display_name: '类型' },
        { key: 'enterpriseCode', display_name: '所属机构' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      var headId = this.$route.query.headId
      this.query.workHeadId = headId
      this.query.isDelete = 1
      return true
    },

    // 查看明细
    toDetail(row) {
      console.log(row.workDetailId)
      this.$router.push({ path: '/orderDetail/secondDetail', query: { workDetailId: row.workDetailId } })
    },

    // 查看明细
    importDetail() {
      console.log("导入数据")
    },
  }
}
</script>

<style scoped>

</style>
